import time

logtime = None
workbook_g = None

def init(workbook = './main.log'):
    global workbook_g
    workbook_g = workbook
    logtime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
    print(f'{logtime}\tlog is set up')

def log(logstr, workbook = None):
    global workbook_g
    if workbook_g == None:
        print('log is not initialized, automacally turning to ./main.log')
        workbook_g = './main.log'
    if workbook == None:
        workbook = workbook_g
    logtime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
    with open(workbook, '+a') as writer:
        writer.write(f'{logtime}\t{logstr}\n')
    print(f'{logtime}\t{logstr}')
